package ESP.Control.L;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;

import ESP.Dao.BaseDao;
import ESP.Util.Mail;

@Controller
public class ForgetPsw {
	@Resource
	public BaseDao baseDao;
	private Map<String, String> message = new HashMap<String, String>();
	
	private String user_id;
	private String user_email;//前台输入邮箱
	private String addressTo;//实际获取邮箱
	private String newPassword;
	/**
	 * 修改密码校验
	 */
	public String checkForgetPsw(){
		addressTo = baseDao.checkForgetPsw(user_id, user_email);
		if (addressTo.equals("")) {
			baseDao.setReturnInfo(message, "N", "输入信息不匹配，请重新输入！");
		}else {
			baseDao.setReturnInfo(message, "Y", addressTo);
		}
		return "ForgetPsw";
	}
	/**
	 * 修改密码 发送密码至用户邮箱
	 */
	public String sendPsw(){
		newPassword = new Mail().sendPsw2mail(addressTo);
		if (newPassword != null) {
			this.baseDao.forgetPsw(user_id, newPassword);
			baseDao.setReturnInfo(message, "Y", "新密码已经成功发送至注册邮箱！");
		}else {
			baseDao.setReturnInfo(message, "N", "新密码未能成功发送，请稍后重试！");
		}
		return "ForgetPsw";
	}
	/**
	 * get set
	 */
	public BaseDao getBaseDao() {
		return baseDao;
	}
	public void setBaseDao(BaseDao baseDao) {
		this.baseDao = baseDao;
	}
	public Map<String, String> getMessage() {
		return message;
	}
	public void setMessage(Map<String, String> message) {
		this.message = message;
	}
	public String getUser_id() {
		return user_id;
	}
	public void setUser_id(String userId) {
		user_id = userId;
	}
	public String getUser_email() {
		return user_email;
	}
	public void setUser_email(String userEmail) {
		user_email = userEmail;
	}
	public String getAddressTo() {
		return addressTo;
	}
	public void setAddressTo(String addressTo) {
		this.addressTo = addressTo;
	}
	public String getNewPassword() {
		return newPassword;
	}
	public void setNewPassword(String newPassword) {
		this.newPassword = newPassword;
	}
}
